package com.youmu.shop.receiver.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youmu.shop.context.utils.UserContext;
import com.youmu.shop.receiver.dao.ReceiverDao;
import com.youmu.shop.receiver.domain.Receiver;
import com.youmu.shop.receiver.service.ReceiverService;
import com.youmu.shop.receiver.vo.AddressVo;
import com.youmu.shop.receiver.vo.AgeGroupInfo;
import com.youmu.shop.receiver.vo.ReceiverVO;
import com.youmu.shop.user.dao.UserDao;

@Service
public class ReceiverServiceImpl implements ReceiverService {

    @Autowired
    private ReceiverDao receiverDao;
    
	@Override
	public List<ReceiverVO> findReceiver(Long userId,Integer isDefault,Long receiveId) {
		return receiverDao.findReceiver(userId,isDefault,receiveId);
	}

	@Override
	public long saveReceiver(Receiver receiver) {
		if(receiver.getIsDefault()){
			receiverDao.cancelDefault(UserContext.getUserInfo().getId());
		}
		return receiverDao.save(receiver);
	}

	@Override
	public void updateReceiver(Receiver receiver) {
		if(receiver.getIsDefault()){
			receiverDao.cancelDefault(UserContext.getUserInfo().getId());
		}
		receiverDao.update(receiver);
	}

	@Override
	public void deleteReceiver(Long id,Long userId) {
		
		receiverDao.update(new Receiver(id,userId,true));
	}

	@Override
	public List<AddressVo> getCity(Integer provinceCode) {
		return receiverDao.getCity(provinceCode);
	}

	@Override
	public List<AddressVo> getDistrict(Integer cityCode) {
		return receiverDao.getDistrict(cityCode);
	}

	@Override
	public List<AddressVo> getProvince() {
		return receiverDao.getProvince();
	}

    
	@Override
    public List<AgeGroupInfo> getAgeGroup(Long groupId) {
        return receiverDao.getAgeGroup(groupId);
    }





}
